<?php
/**
 * 区域 下拉联动
 * @author jiang
 */
define ( 'IN_templates', "admin" );
include (dirname(__FILE__)."/../includes/init.php");//全局变量

$act=isset($_POST['act'])?$fun->checkInput(trim($_POST['act'])):"";

switch($act){
	case "citysel"://城市
		$province = isset($_POST['province'])?trim($_POST['province']):"";
		//type=1表示查询有选择 type=2表示下拉查询 0表示没有 下拉添加修改用
		$type = isset($_POST['type'])?intval($_POST['type']):"0";
		$city = isset($_POST['city'])?trim($_POST['city']):"";
		$css =isset($_POST['css'])?trim($_POST['css']):"";
		if($province){
			$selectCity = $db->get_all("SELECT infoid, title FROM `{$tbprefix}area` WHERE parentid='".$province."' AND `ishow`='1' AND `is_valid`='1' AND 1 ORDER BY `orderid` DESC");
			if($type == 1){
				echo '<select name="city" id="city" class="'.$css.'" style="display:block;" ><option value="0">选择市</option>';
				foreach($selectCity as $k => $v){
					echo '<option ';
					if($city == $v['infoid']){
						echo "selected='selected'";
					}
					echo ' value="'.$v['infoid'].'">'.$v['title'].'</option>';
				}
				echo '</select>';
			}elseif($type == 2){
				echo '<select name="city" id="city" class="'.$css.'" style="display:block;" onchange="return formSubmit();"><option value="0">选择市</option>';
				foreach($selectCity as $k => $v){
					echo '<option ';
					if($city == $v['infoid']){
						echo "selected='selected'";
					}
					echo ' value="'.$v['infoid'].'">'.$v['title'].'</option>';
				}
				echo '</select>';
	
			}elseif($type == 3){
				echo '<select name="city" id="city" class="'.$css.'" style="display:block;" onchange="return loadArea(\'3\',\'\');"><option value="0">选择市</option>';
				foreach($selectCity as $k => $v){
					echo '<option ';
					if($city == $v['infoid']){
						echo "selected='selected'";
					}
					echo ' value="'.$v['infoid'].'">'.$v['title'].'</option>';
				}
				echo '</select>';
	
			}
			else{
				echo '<select name="city" id="city" class="'.$css.'" style="display:block;"><option value="0">选择市</option>';
				foreach($selectCity as $k => $v){
					echo '<option value="'.$v['infoid'].'">'.$v['title'].'</option>';
				}
				echo '</select>';
			}
		}else{
			echo '<select name="city" id="city" class="'.$css.'" style="display:block;" '.($type == 2?'onchange="return formSubmit();"':'').'><option value="0">选择市</option></select>';
		}
	
		break;
		
	case "areasel"://城市
		$city = isset($_POST['city'])?trim($_POST['city']):"";
		//type=1表示查询有选择 type=2表示下拉查询 0表示没有 下拉添加修改用
		$type = isset($_POST['type'])?intval($_POST['type']):"0";
		$area = isset($_POST['area'])?trim($_POST['area']):"";
		$css =isset($_POST['css'])?trim($_POST['css']):"";
		if($city){
			$selectArea = $db->get_all("SELECT infoid, title FROM `{$tbprefix}area` WHERE parentid='".$city."' AND `ishow`='1' AND `is_valid`='1' AND 1 ORDER BY `orderid` DESC");
			if($type == 1){
				echo '<select name="area" id="area" class="'.$css.'" style="display:block;" ><option value="0">选择区</option>';
				foreach($selectArea as $k => $v){
					echo '<option ';
					if($area == $v['infoid']){
						echo "selected='selected'";
					}
					echo ' value="'.$v['infoid'].'">'.$v['title'].'</option>';
				}
				echo '</select>';
			}elseif($type == 2){
				echo '<select name="area" id="area" class="'.$css.'" style="display:block;"><option value="0">选择区</option>';
				foreach($selectArea as $k => $v){
					echo '<option ';
					if($area == $v['infoid']){
						echo "selected='selected'";
					}
					echo ' value="'.$v['infoid'].'">'.$v['title'].'</option>';
				}
				echo '</select>';
	
			}elseif($type == 3){
				echo '<select name="area" id="area" class="'.$css.'" style="display:block;"><option value="0">选择区</option>';
				foreach($selectArea as $k => $v){
					echo '<option ';
					if($area == $v['infoid']){
						echo "selected='selected'";
					}
					echo ' value="'.$v['infoid'].'">'.$v['title'].'</option>';
				}
				echo '</select>';
	
			}
			else{
				echo '<select name="area" id="area" class="'.$css.'" style="display:block;"><option value="0">选择区</option>';
				foreach($selectArea as $k => $v){
					echo '<option value="'.$v['infoid'].'">'.$v['title'].'</option>';
				}
				echo '</select>';
			}
		}else{
			echo '<select name="area" id="area" class="'.$css.'" style="display:block;" '.($type == 2?'onchange="return formSubmit();"':'').'><option value="0">选择区</option></select>';
		}
	
		break;

	case "":
		echo $msg="加载失败...";
		break;

	default:
		$msg='{"root":[{"status":"false","Description":"操作失败"}]}';
		break;
}

?>